package com.qf.service.impl;

import com.qf.controller.StuClassController;
import com.qf.entity.ClassRoom;
import com.qf.entity.Stu;
import com.qf.entity.StuVO;
import com.qf.mapper.StuClassMapper;
import com.qf.service.StuClassService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Qiao
 * @date 2025/8/16
 * @desc
 */
@Service
public class StuClassServiceImpl implements StuClassService {

    @Autowired
    private StuClassMapper stuClassMapper;
    @Override
    public List<StuVO> findStuAndClassRoomAll() {
        // 定义最后返回的数据
        List<StuVO> list = new ArrayList<>();
        // 查所有学生的信息
        List<Stu> stuList = stuClassMapper.findStuAll();
        // 遍历学生数据
        stuList.forEach(stu->{
            ClassRoom classRoom = stuClassMapper.findClass(stu.getCid());

            StuVO stuVO = new StuVO();
            BeanUtils.copyProperties(stu,stuVO);
            stuVO.setClassRoom(classRoom);
            list.add(stuVO);
        });


        return list;
    }
}
